package com.atguigu.guli.service.edu.controller.admin;


import com.atguigu.guli.service.base.result.R;
import com.atguigu.guli.service.edu.entity.Chapter;
import com.atguigu.guli.service.edu.service.ChapterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author atguigu
 * @since 2021-10-26
 */
@RestController

@RequestMapping("admin/edu/chapter")
public class AdminChapterController {
    @Autowired
    ChapterService chapterService;
//新增章节信息
    @PostMapping("addChapter")
    public R addChapter(@RequestBody Chapter chapter){
        boolean save = chapterService.save(chapter);
        return R.ok();
    }
    //修改章节信息
    @PutMapping("editChapter")
    public R editChapter(@RequestBody Chapter chapter){
        chapterService.updateById(chapter);
        return R.ok();
    }
    //删除章节信息
    @DeleteMapping("deleteChapter/{id}")
    public R deleteChapter(@PathVariable String id){
        chapterService.removeById(id);
        return R.ok();
    }
    //根据id查询章节信息
    @GetMapping("getChapterById/{id}")
    public R getChapterById(@PathVariable String id){
        Chapter chapter = chapterService.getById(id);
        return R.ok().data("item",chapter);
    }
    //根据课程查询课程对应的所有章节的信息
    @GetMapping("getChapter/{id}")
    public R getChapter(@PathVariable String id){
    List<Chapter> chapterList =  chapterService.getChapterByCounterId(id);
    return R.ok().data("items",chapterList);
    }
}




